﻿using FingerTip.Domain.Apps.Commands;
using FingerTip.Framework.Commands;
using FingerTip.Framework.Events;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;

namespace FingerTip.Domain.Apps.Handlers
{
    public class CreateAppHandler:ICommandHandler<CreateApp>
    {
        private readonly IAppRepository appRepository;
        private readonly IValidator<CreateApp> validator;

        public CreateAppHandler(IAppRepository appRepository,IValidator<CreateApp> validator)
        {
            this.appRepository = appRepository;
            this.validator = validator;
        }

        public IEnumerable<IEvent> Handle(CreateApp command)
        {
            var app = App.CreateNew(command, validator);
            appRepository.Create(app);
            return app.Events;
        }
    }
}
